/***********************************************
 This file is part of redia-lib-utils-ios
 
 
 Copyright (c) 2015 Redia A/S
 
 Redia-library-app-ios is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 Redia-library-app-ios is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with redia-library-app-ios.  If not, see <http://www.gnu.org/licenses/>.
 
 *********************************************** */

#import "RDLightFrameButton.h"

@implementation RDLightFrameButton

-(void)commonLightFrameButtonInit
{
    self.borderWidth = 1;
}

-(id)init
{
    self = [super init];
    if (self) {
        [self commonLightFrameButtonInit];
    }
    return self;
}

-(id)initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self commonLightFrameButtonInit];
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self commonLightFrameButtonInit];
    }
    return self;
}


-(void)awakeFromNib{
    
    self.layer.borderWidth = self.borderWidth;
    
    if (self.normalColor == nil) {
        self.normalColor = self.backgroundColor;
    }
    
    if (self.highlightColor == nil) {
        self.highlightColor = self.normalColor;
    }
    
    if (self.selectedColor == nil) {
        self.selectedColor = self.normalColor;
    }
    
    if (self.borderNormalColor == nil) {
        self.borderNormalColor = [UIColor clearColor];
    }
    
    if (self.borderHighlightColor == nil) {
        self.borderHighlightColor = self.normalColor;
    }
    
    if (self.borderSelectedColor == nil) {
        self.borderSelectedColor = self.normalColor;
    }
    
    if (self.selected) {
        self.backgroundColor = self.selectedColor;
        self.layer.borderColor = self.borderSelectedColor.CGColor;
    }
    else{
        self.backgroundColor = self.normalColor;
        self.layer.borderColor = self.borderNormalColor.CGColor;
    }
    
}

-(void)setHighlighted:(BOOL)highlighted{
    [super setHighlighted:highlighted];
    if (highlighted) {
        self.backgroundColor = self.highlightColor;
        self.layer.borderColor = self.borderHighlightColor.CGColor;
    }
    else if (self.selected) {
        self.backgroundColor = self.selectedColor;
        self.layer.borderColor = self.borderSelectedColor.CGColor;
    }
    else{
        self.backgroundColor = self.normalColor;
        self.layer.borderColor = self.borderNormalColor.CGColor;
    }
}

-(void)setSelected:(BOOL)selected{
    [super setSelected:selected];
    if (selected) {
        self.backgroundColor = self.selectedColor;
        self.layer.borderColor = self.borderSelectedColor.CGColor;
    }
    else{
        self.backgroundColor = self.normalColor;
        self.layer.borderColor = self.borderNormalColor.CGColor;
    }
}


@end
